module klang.编译.Align.Align_;
import 全局;
import klang.编译.APInt.APInt_: Log2_64;
import klang.编译.核心.核心_: 返回零值;
enum Dims_ : uint {
    FixedDim = 0u,
    ScalableDim = 1u
}
class LogValue_ {
    ubyte log;
    this() { }
    this(ubyte _log) {
        this.log = _log;
    }
}
class Align_ {
    ubyte ShiftValue = 0;
    this() { }
    this(ulong v) {
        this.ShiftValue = Log2_64(v);
    }
    this(LogValue_ CA) {
        this.ShiftValue = CA.log;
    }
    ulong value() {
        return 1 << this.ShiftValue;
    }
    bool Op大于等于(Align_ Rhs) {
        return this.ShiftValue >= Rhs.ShiftValue;
    }
    bool Op小于(Align_ Rhs) {
        return this.ShiftValue < Rhs.ShiftValue;
    }
}
class 动态值_(T) {
    Dims_ UnivariateDim;
    T Val;
    this() {
        this.Val = 返回零值!(T)();
        this.UnivariateDim = Dims_.FixedDim;
    }
    this(T V, Dims_ Dim) {
        this.Val = V;
        this.UnivariateDim = Dim;
    }
    this(T V, bool Dim) {
        this.Val = V;
        this.UnivariateDim = Dim ? Dims_.ScalableDim : Dims_.FixedDim;
    }
    动态值_!(T) p·getFixed(T V) {
        this.Val = V;
        this.UnivariateDim = Dims_.FixedDim;
        return this;
    }
    动态值_!(T) p·getScalable(T V) {
        this.Val = V;
        this.UnivariateDim = Dims_.ScalableDim;
        return this;
    }
    动态值_!(T) getNull() {
        this.Val = 返回零值!(T)();
        this.UnivariateDim = Dims_.FixedDim;
        return this;
    }
    T getValue() {
        return this.Val;
    }
    T getKnownMinValue() {
        return this.getValue();
    }
    bool isScalable() {
        return this.UnivariateDim == Dims_.ScalableDim;
    }
    T getFixedValue() {
        assert(!this.isScalable(), "xxx"c);
        return this.getKnownMinValue();
    }
    bool p·Op等等(动态值_!(T) RHS) {
        return this.Val == RHS.Val && this.UnivariateDim == RHS.UnivariateDim;
    }
}
class TypeSize : 动态值_!(ulong) {
    this() {
        super(0, false);
    }
    this(ulong V, Dims_ Dim) {
        super(V, Dim);
    }
    this(ulong V, bool Dim) {
        super(V, Dim);
    }
    ulong getFixedSize() {
        return this.getFixedValue();
    }
    ulong getKnownMinSize() {
        return this.getKnownMinValue();
    }
    ulong Op值() {
        if (this.isScalable()) {
            return this.getKnownMinSize();
        }
        return this.getFixedSize();
    }
}
class ElementCount : 动态值_!(uint) {
    this() {
        super(0, false);
    }
    this(uint V, Dims_ Dim) {
        super(V, Dim);
    }
    this(uint V, bool Dim) {
        super(V, Dim);
    }
    bool isScalar() {
        return !this.isScalable() && this.getKnownMinValue() == 1;
    }
    bool isVector() {
        return this.isScalable() && this.getKnownMinValue() == 0 || this.getKnownMinValue() > 1;
    }
    bool isZero() { return this.Val == 0; }
    bool isNonZero() { return !this.isZero(); }
}
TypeSize Fixed(ulong V) {
    return new TypeSize(V, false);
}
TypeSize Scalable(ulong V) {
    return new TypeSize(V, true);
}
TypeSize alignTo(TypeSize Size, ulong Align) {
    assert(Align != 0u, "Align must be non-zero"c);
    return new TypeSize(Size.getKnownMinValue() + Align - 1, Size.isScalable());
}
ElementCount ECFixed(uint V) {
    return new ElementCount(V, false);
}
